Related articles |
---|
Precedence values for Reverse Polish nerd@freeuk.com (Nerd) (1999-10-27) |
Re: Precedence values for Reverse Polish cbrtjr@ix.netcom.com (Charles E. Bortle, Jr.) (1999-10-29) |
Re: Precedence values for Reverse Polish lex@cc.gatech.edu (1999-10-31) |
Re: Precedence values for Reverse Polish ppaatt@aol.com (1999-10-31) |
Re: Precedence values for Reverse Polish nerd@freeuk.com (Nerd) (1999-10-31) |
Re: Precedence values for Reverse Polish anton@mips.complang.tuwien.ac.at (1999-11-02) |
Re: Precedence values for Reverse Polish ppaatt@aol.com (1999-11-02) |
Re: Precedence values for Reverse Polish anton@mips.complang.tuwien.ac.at (1999-11-03) |
[3 later articles] |
From: | "Charles E. Bortle, Jr." <cbrtjr@ix.netcom.com> |
Newsgroups: | comp.compilers |
Date: | 29 Oct 1999 02:35:33 -0400 |
Organization: | MindSpring Enterprises |
References: | 99-10-124 |
Keywords: | parse |
Hello Paul,
Below I have listed the <EXPRESSION> definitions extracted from an
(almost) LL1 grammar that I wrote for Turbo Pascal 3. Perhaps you
can work though it and figure out how to modify you routines?
Also, on my personal web sit (URL in my sig.) I present (General Programming
Issue #1) pseudo-code for an interpreter using the Bauer-Samelson Algorithm.
It only handles the operators you are already processing, but the entire
article may
help you figure it out?
<EXPRESSION> ::= <SIMPLE EXPRESSION> #COPY($1,$2) <EXPRESSION TAIL>
#COPY($2,$$)
<EXPRESSION TAIL> ::= #COPY($$,$1) <RELATIONAL PHRASE> #COPY($1,$2)
<EXPRESSION TAIL> #COPY($2,$$)
<EXPRESSION TAIL> ::= <EMPTY>
<RELATIONAL PHRASE> ::= <RELATIONAL OPERATOR> <SIMPLE EXPRESSION>
#PROCESS_INFIX_OPERATION($$,$1,$2,$$)
<RELATIONAL OPERATOR> ::= EQUALS_SIGN #PROCESS_RELATIONAL_OPERATOR($1,$$)
<RELATIONAL OPERATOR> ::= NOT_EQUAL #PROCESS_RELATIONAL_OPERATOR($1,$$)
<RELATIONAL OPERATOR> ::= LESS_THAN_OR_EQUAL_TO
#PROCESS_RELATIONAL_OPERATOR($1,$$)
<RELATIONAL OPERATOR> ::= GREATER_THAN_OR_EQUAL_TO
#PROCESS_RELATIONAL_OPERATOR($1,$$)
<RELATIONAL OPERATOR> ::= LESS_THAN #PROCESS_RELATIONAL_OPERATOR($1,$$)
<RELATIONAL OPERATOR> ::= GREATER_THAN #PROCESS_RELATIONAL_OPERATOR($1,$$)
<RELATIONAL OPERATOR> ::= IN #PROCESS_RELATIONAL_OPERATOR($1,$$)
<SIMPLE EXPRESSION> ::= <TERM> #COPY($1,$2) <SIMPLE EXPRESSION TAIL>
#COPY($2,$$)
<SIMPLE EXPRESSION TAIL> ::= <ADDING OPERATOR> <TERM>
#PROCESS_INFIX_OPERATION($$,$1,$2,$3) <SIMPLE EXPRESSION TAIL> #COPY($3,$$)
<SIMPLE EXPRESSION TAIL> ::= <EMPTY>
<ADDING OPERATOR> ::= + #PROCESS_ADDING_OPERATOR($1,$$)
<ADDING OPERATOR> ::= - #PROCESS_ADDING_OPERATOR($1,$$)
<ADDING OPERATOR> ::= OR #PROCESS_ADDING_OPERATOR($1,$$)
<ADDING OPERATOR> ::= XOR #PROCESS_ADDING_OPERATOR($1,$$)
<TERM> ::= <COMPLEMENTED FACTOR> #COPY($1,$2) <TERM TAIL> #COPY($2,$$)
<TERM TAIL> ::= <MULTIPLYING OPERATOR> <COMPLEMENTED FACTOR>
#PROCESS_INFIX_OPERATION($$,$1,$2,$3) <TERM TAIL> #COPY($3,$$)
<TERM TAIL> ::= <EMPTY>
<MULTIPLYING OPERATOR> ::= ASTERISK #PROCESS_MULTIPLYING_OPERATOR($1,$$)
<MULTIPLYING OPERATOR> ::= / #PROCESS_MULTIPLYING_OPERATOR($1,$$)
<MULTIPLYING OPERATOR> ::= DIV #PROCESS_MULTIPLYING_OPERATOR($1,$$)
<MULTIPLYING OPERATOR> ::= MOD #PROCESS_MULTIPLYING_OPERATOR($1,$$)
<MULTIPLYING OPERATOR> ::= AND #PROCESS_MULTIPLYING_OPERATOR($1,$$)
<MULTIPLYING OPERATOR> ::= SHL #PROCESS_MULTIPLYING_OPERATOR($1,$$)
<MULTIPLYING OPERATOR> ::= SHR #PROCESS_MULTIPLYING_OPERATOR($1,$$)
<COMPLEMENTED FACTOR> ::= <SIGNED FACTOR> #COPY($1,$$)
<COMPLEMENTED FACTOR> ::= NOT <SIGNED FACTOR>
#PROCESS_UNARY_NOT_OPERATION($2,$$)
<SIGNED FACTOR> ::= <FACTOR> #COPY($1,$$)
<SIGNED FACTOR> ::= <SIGN> <FACTOR> #PROCESS_UNARY_SIGN_OPERATION($1,$2,$$)
<FACTOR> ::= <VARIABLE OR FUNCTION DESIGNATOR> #COPY($1,$$)
<FACTOR> ::= <UNSIGNED CONSTANT> #COPY($1,$$)
<FACTOR> ::= ( <EXPRESSION> ) #COPY($2,$$)
<FACTOR> ::= <SET CONSTRUCTOR> #COPY($1,$$)
<VARIABLE OR FUNCTION DESIGNATOR> ::= <ID> <VAR OR FUNC DESIG TAIL>
<VARIABLE OR FUNCTION DESIGNATOR> ::= <STANDARD FUNCTIONS>
<VAR OR FUNC DESIG TAIL> ::= <SPECIAL VARIABLE TAIL>
<VAR OR FUNC DESIG TAIL> ::= <ACTUAL PROCEDURE OR FUNCTION PARAMS>
<VAR OR FUNC DESIG TAIL> ::= <EMPTY>
<UNSIGNED CONSTANT> ::= <UNSIGNED NUMBER> #COPY($1,$$)
<UNSIGNED CONSTANT> ::= <STRING> #COPY($1,$$)
<UNSIGNED CONSTANT> ::= NIL #COPY($1,$$)
<SET CONSTRUCTOR> ::= [ <SET ELEMENT LIST> ] #PROCESS_SET_CONSTRUCTOR($2,$$)
<SET ELEMENT LIST> ::= <SET ELEMENT> #START_SET_ELEMENT_LIST($1,$2) <SET
ELEMENT LIST TAIL> #COPY($2,$$)
<SET ELEMENT LIST> ::= <EMPTY>
<SET ELEMENT LIST TAIL> ::= , <SET ELEMENT>
#NEXT_SET_ELEMENT_LIST_ENTRY($2,$$) #COPY($$,$3) <SET ELEMENT LIST TAIL>
#COPY($3,$$)
<SET ELEMENT LIST TAIL> ::= <EMPTY>
<SET ELEMENT> ::= <EXPRESSION> #PROCESS_SET_ELEMENT_RANGE_BEGINNNG($1,$2)
<SET ELEMENT TAIL> #COPY($2,$$)
<SET ELEMENT TAIL> ::= DOT_DOT <EXPRESSION>
#PROCESS_SET_ELEMENT_RANGE_ENDING($2,$$)
<SET ELEMENT TAIL> ::= <EMPTY>
--
Charles cbrtjr@ix.netcom.com
* http://pw2.netcom.com/~cbrtjr/wrdthing.html *
Return to the
comp.compilers page.
Search the
comp.compilers archives again.