Skip to content
This repository has been archived by the owner on Feb 3, 2021. It is now read-only.

Commit

Permalink
Initial steps for operator precedence parsing via
Browse files Browse the repository at this point in the history
the magic <O(...)> subrule.  :-)
  • Loading branch information
pmichaud committed Oct 19, 2009
1 parent c2b8fd7 commit a27d5d1
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 2 deletions.
3 changes: 3 additions & 0 deletions build/Makefile.in
Expand Up @@ -38,6 +38,8 @@ NQP_LANG_DIR = $(PARROT_LIB_DIR)/languages/nqp

P6REGEX_SOURCES = \
src/Regex/P6Regex.pir \
src/Regex/P6Regex/Grammar.pm \
src/Regex/P6Regex/Actions.pm \
src/cheats/p6regex-grammar.pir \
src/cheats/hll-compiler.pir \
src/cheats/regex-cursor-protoregex.pir \
Expand All @@ -58,6 +60,7 @@ NQP_SOURCES = \
src/NQP/Grammar.pm \
src/NQP/Actions.pm \
src/NQP/Compiler.pir \
src/cheats/nqp-grammar.pir \

STAGE0 = src/stage0
STAGE1 = src/stage1
Expand Down
5 changes: 4 additions & 1 deletion src/NQP/Actions.pm
@@ -1,6 +1,9 @@
class NQP::Actions;

method TOP($/) {
NQP::Grammar.O(':prec<u=>, :assoc<left>', '%multiplicative');
NQP::Grammar.O(':prec<t=>, :assoc<left>', '%additive');

method TOPx($/) {
make $<value>.ast;
}

Expand Down
2 changes: 2 additions & 0 deletions src/NQP/Compiler.pir
Expand Up @@ -38,6 +38,8 @@ NQP::Compiler - NQP compiler
.end


.include 'src/cheats/nqp-grammar.pir'

=cut

# Local Variables:
Expand Down
9 changes: 8 additions & 1 deletion src/NQP/Grammar.pm
Expand Up @@ -3,7 +3,7 @@ grammar NQP::Grammar;
token starter { \" }
token stopper { \" }

token TOP { <value> }
token TOP { <infix>* }

token value {
| <integer>
Expand Down Expand Up @@ -64,3 +64,10 @@ token charspec {
| <.panic: 'Unrecognized \\c character'>
]
}

proto token infix { <...> }
token infix:sym<+> { '+' <O('%additive , :pirop<add>')> }
token infix:sym<-> { '-' <O('%additive , :pirop<sub>')> }
token infix:sym<*> { '*' <O('%multiplicative , :pirop<mul>')> }
token infix:sym</> { '/' <O('%multiplicative , :pirop<div>')> }

0 comments on commit a27d5d1

Please sign in to comment.