[Commit] mint/src mint-parser.5c,1.1,1.2
Bart Massey
commit at keithp.com
Sat Jan 15 23:43:53 PST 2005
Committed by: bart
Update of /local/src/CVS/mint/src
In directory home.keithp.com:/tmp/cvs-serv12947/src
Modified Files:
mint-parser.5c
Log Message:
Changed token syntax for lolgram.mnt slightly.
Added convenience routines, reference-passing to mint-parser.5c.
Index: mint-parser.5c
===================================================================
RCS file: /local/src/CVS/mint/src/mint-parser.5c,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -d -r1.1 -r1.2
--- mint-parser.5c 13 Jan 2005 09:24:48 -0000 1.1
+++ mint-parser.5c 16 Jan 2005 07:43:50 -0000 1.2
@@ -43,18 +43,37 @@
load "lexer_io.5c"
namespace MintParser {
+ /* more friendly syntax error exception: line number and message */
public exception syntax_error(int, string);
- public ast parse_file(string mntbase, string target) {
+ public &ast parse_file(string mntbase, string target)
+ /* lex and parse a file given the serialized lexer
+ and parser at the given address */
+ {
lexer lex = load_lexer(mntbase + ".mtl");
parse_table ptbl = load_parser(mntbase + ".mtp");
file f = open(target, "r");
try {
- ast a = Mint::parse_file(&ptbl, &lex, f);
+ &ast a = &Mint::parse_file(&ptbl, &lex, f);
} catch syntax_error(&lexer_context lc) {
raise syntax_error(lc.line_number, get_token(&lc).lexeme);
}
- return a;
+ return &a;
}
-}
+ public &ast get_nonterminal(&ast a, string path ...)
+ /* Convenience routine: walk down a parse tree to a nonterminal */
+ {
+ for (int i = 0; i < dim(path); i++)
+ &a = &a.nonterminal.fields[path[i]];
+ return &a;
+ }
+
+ public &token get_terminal(&ast a, string path ...)
+ /* Convenience routine: walk down a parse tree to a terminal */
+ {
+ for (int i = 0; i < dim(path); i++)
+ &a = &a.nonterminal.fields[path[i]];
+ return &a.terminal;
+ }
+}
More information about the Commit
mailing list