Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Comparing changes

Choose two branches to see what's changed or to start a new pull request. If you need to, you can also compare across forks.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also compare across forks.
base fork: wbhart/Cesium3
base: 57bca279bf
...
head fork: wbhart/Cesium3
compare: d669282164
  • 5 commits
  • 4 files changed
  • 0 commit comments
  • 1 contributor
Showing with 65 additions and 8 deletions.
  1. +7 −6 Makefile
  2. +1 −1  ast.h
  3. +55 −1 parser.c
  4. +2 −0  parser.h
View
13 Makefile
@@ -1,22 +1,23 @@
INC=-I/home/wbhart/gc/include
LIB=-L/home/wbhart/gc/lib
OBJS=symbol.o input.o ast.o exception.o parser.o
+HEADERS=ast.h exception.h parser.h input.h symbol.h
-cesium: cesium.c $(OBJS)
+cesium: cesium.c $(HEADERS) $(OBJS)
gcc -O2 -o cesium cesium.c $(INC) $(OBJS) $(LIB) -lgc
-ast.o: ast.c ast.h
+ast.o: ast.c $(HEADERS)
gcc -c -O2 -o ast.o ast.c $(INC)
-exception.o: exception.c exception.h
+exception.o: exception.c $(HEADERS)
gcc -c -O2 -o exception.o exception.c $(INC)
-parser.o: parser.c parser.h
+parser.o: parser.c $(HEADERS)
gcc -c -O2 -o parser.o parser.c $(INC)
-input.o: input.c input.h
+input.o: input.c $(HEADERS)
gcc -c -O2 -o input.o input.c $(INC)
-symbol.o: symbol.c symbol.h
+symbol.o: symbol.c $(HEADERS)
gcc -c -O2 -o symbol.o symbol.c $(INC)
View
2  ast.h
@@ -32,7 +32,7 @@ ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
typedef enum
{
- T_NONE, T_LIST, T_INT, T_ADD, T_SUB, T_MUL, T_DIV, T_REM
+ T_NONE, T_LIST, T_INT, T_ADD, T_SUB, T_MUL, T_DIV, T_REM, T_IDENT
} tag_t;
typedef struct ast_t
View
56 parser.c
@@ -228,13 +228,15 @@ combinator_t * anything()
ast_t * integer_fn(input_t * in, void * args)
{
- int start = in->start, len;
+ int start, len;
char c, * text;
ast_t * ast = new_ast();
skip_whitespace(in);
+ start = in->start;
+
c = read1(in);
if (!isdigit(c))
@@ -246,6 +248,9 @@ ast_t * integer_fn(input_t * in, void * args)
if (c == '0')
{
ast->typ = T_INT;
+
+ ast->sym = sym_lookup("0");
+
return ast;
}
@@ -274,6 +279,51 @@ combinator_t * integer()
return comb;
}
+ast_t * cident_fn(input_t * in, void * args)
+{
+ int start, len;
+ char c, * text;
+
+ ast_t * ast = new_ast();
+
+ skip_whitespace(in);
+
+ start = in->start;
+
+ c = read1(in);
+
+ if (c != '_' && !isalpha(c))
+ {
+ in->start = start;
+ return NULL;
+ }
+
+ while ((c = read1(in)) == '_' || isalpha(c) || isdigit(c)) ;
+ in->start--;
+
+ ast->typ = T_IDENT;
+
+ len = in->start - start;
+
+ text = GC_MALLOC(len + 1);
+
+ strncpy(text, in->input + start, len);
+ text[len] = '\0';
+
+ ast->sym = sym_lookup(text);
+
+ return ast;
+}
+
+combinator_t * cident()
+{
+ combinator_t * comb = new_combinator();
+ comb->fn = cident_fn;
+ comb->args = NULL;
+
+ return comb;
+}
+
seq_list * new_seq()
{
return GC_MALLOC(sizeof(seq_list));
@@ -281,6 +331,7 @@ seq_list * new_seq()
ast_t * seq_fn(input_t * in, void * args)
{
+ int start = in->start;
seq_args * sa = (seq_args *) args;
seq_list * seq = sa->list;
@@ -293,7 +344,10 @@ ast_t * seq_fn(input_t * in, void * args)
{
ast_t * a = parse(in, seq->comb);
if (a == NULL)
+ {
+ in->start = start;
return NULL;
+ }
if (a != ast_nil)
{
View
2  parser.h
@@ -106,6 +106,8 @@ combinator_t * exact(char * str);
combinator_t * integer();
+combinator_t * cident();
+
combinator_t * range(char * str);
combinator_t * alpha();

No commit comments for this range

Something went wrong with that request. Please try again.