[svn:parrot] r39907 - in branches/ops_pct/compilers/opsc: . compiler

cotto at svn.parrot.org cotto at svn.parrot.org
Tue Jul 7 07:10:24 UTC 2009


Author: cotto
Date: Tue Jul  7 07:10:20 2009
New Revision: 39907
URL: https://trac.parrot.org/parrot/changeset/39907

Log:
[opsc] add enough parser code to parse a single op, although not usefully

Modified:
   branches/ops_pct/compilers/opsc/compiler/grammar.pg
   branches/ops_pct/compilers/opsc/opsc.pir

Modified: branches/ops_pct/compilers/opsc/compiler/grammar.pg
==============================================================================
--- branches/ops_pct/compilers/opsc/compiler/grammar.pg	Tue Jul  7 05:01:35 2009	(r39906)
+++ branches/ops_pct/compilers/opsc/compiler/grammar.pg	Tue Jul  7 07:10:20 2009	(r39907)
@@ -0,0 +1,80 @@
+# Copyright (C) 2009, Parrot Foundation.
+# $Id$
+
+
+grammar Ops::Grammar is PCT::Grammar;
+
+token TOP {
+    <ops>
+    [ $ || <panic: 'Syntax error'> ]
+    {*}
+}
+
+rule ops {
+    <op>*
+}
+
+rule op {
+    <op_type> 'op' <op_name=identifier> '(' <op_params>? ')' <op_flag>* 
+    '{' ~ '}' <op_body>
+}
+
+token op_type {
+    [ 'inline' | 'function' ]
+}
+
+rule op_params {
+    <op_param> [ ',' <op_param> ]*
+}
+
+rule op_param {
+    <op_param_direction> <op_param_type> 
+}
+
+rule op_param_direction {
+    [ 'in' | 'out' | 'inout' | 'inconst' | 'invar' ]   
+}
+
+rule op_param_type {
+    [ 'INT' | 'NUM' | 'STR' | 'PMC' | 'KEY' | 'INTKEY' | 'LABEL' ]
+}
+
+rule op_flag {
+    ':' <identifier> 
+}
+
+rule op_body {
+    <op_body_guts> [ '{' ~ '}' <op_body>  <op_body_guts> ]?
+}
+
+regex op_body_guts {
+    <not_special> [ <special_thingy> <not_special> ]*
+}
+
+regex not_special {
+    <-[{}$]>*
+}
+
+rule special_thingy {
+    [ <param_placeholder> ]
+}
+
+rule param_placeholder {
+    '$' <placeholder_digit>
+}
+
+token placeholder_digit {
+    <.digit>
+}
+
+token identifier {
+    <.ident>
+}
+
+
+
+
+
+
+
+# vim: expandtab shiftwidth=4 ft=perl6:

Modified: branches/ops_pct/compilers/opsc/opsc.pir
==============================================================================
--- branches/ops_pct/compilers/opsc/opsc.pir	Tue Jul  7 05:01:35 2009	(r39906)
+++ branches/ops_pct/compilers/opsc/opsc.pir	Tue Jul  7 07:10:20 2009	(r39907)
@@ -16,7 +16,7 @@
     $P0 = new [ 'Ops';'Compiler' ]
     $P0.'language'('Ops')
     $P0.'parsegrammar'('Ops::Grammar')
-    $P0.'parseactions'('Ops::Grammar::Actions')
+    #$P0.'parseactions'('Ops::Grammar::Actions')
 
     #these stages aren't currently used, although generate_files exits before
     #they can be called anyway
@@ -24,107 +24,12 @@
     $P0.'removestage'('pir')
     $P0.'removestage'('evalpmc')
 
-    #add an extra stage to generate the c, h and dump files
-    #$P0.'addstage'('generate_files', 'after'=>'past')
-    #$P0.'addstage'('read_dump', 'before'=>'parse')
-
-    $P1 = split ' ', 'e=s vtdump|d=s pmc_path|p=s help|h target=s dumper=s trace|t=s encoding=s output|o=s combine version|v'
-    setattribute $P0, '@cmdoptions', $P1
-
-.end
-
-.sub 'generate_files' :method
-    .param pmc past
-    .param pmc adverbs :slurpy :named
-
-    .local string pmc_dir, pmc_name, vtdump_str, vtdump_filename
-    .local pmc pmc_filename, emitter, vtdump
-
-    vtdump_filename = adverbs['vtdump']
-    if vtdump_filename != '' goto read_dump
-    #temporary code to make manually running pmcc simpler
-    vtdump_filename = '../../vtable.frozen'
-    #$P0 = getstderr
-    #print $P0, "Error: no vtable.freeze specified."
-  read_dump:
-    $P0 = new ['FileHandle']
-    vtdump_str = $P0.'readall'(vtdump_filename)
-    vtdump = thaw vtdump_str
-
-    pmc_filename = get_hll_global ['PMC';'Emitter'], '$?filename'
-    $P0          = get_hll_global ['PMC';'Emitter'], '$?pmc_name'
-    pmc_name = $P0
-
-    #XXX: Splitting paths based on '/' is too simplistic.
-    pmc_dir = pmc_filename
-    $P1 = split '/', pmc_dir
-    $I0 = $P1
-    delete $P1[$I0]
-    pmc_dir = join '/', $P1
-
-    unless pmc_dir == '' goto emit_files
-    pmc_dir = '.'
-
-  emit_files:
-    .local string dump_filename, c_filename, header_filename
-    .local string dump_contents, c_contents, header_contents
-
-    emitter = new ['PMC';'Emitter']
-    emitter.'set_vtable_info'(vtdump)
-
-    c_filename = concat pmc_dir, '/'
-    c_filename = concat c_filename, pmc_name
-    c_filename = concat c_filename, '.c'
-    c_contents = emitter.'generate_c_code'(past)
-    write_file(c_filename, c_contents)
-
-    header_filename = concat pmc_dir, '/pmc_'
-    header_filename = concat header_filename, pmc_name
-    header_filename = concat header_filename, '.h'
-    header_contents = emitter.'generate_header'(past)
-    write_file(header_filename, header_contents)
-
-    dump_filename = concat pmc_dir, '/'
-    dump_filename = concat dump_filename, pmc_name
-    dump_filename = concat dump_filename, '.dump'
-    dump_contents = emitter.'generate_dump'(past)
-    write_file(dump_filename, dump_contents)
-
-    #there's nothing left to do, so exit and avoid any extra output
-    exit 0
-.end
-
-
-.sub 'write_file'
-    .param string name
-    .param string contents
-
-    .local pmc fh
-    fh = new ['FileHandle']
-    fh.'open'(name, 'w')
-    print fh, contents
-    fh.'close'()
-    print "wrote output to "
-    say name
-    .return ()
-
-  cant_write:
-    .local pmc ex
-    .local string msg
-    .get_results (ex)
-    msg = ex
-    print "ERROR: couldn't open "
-    print name
-    print " for writing: "
-    say ex
-    .return ()
-
 .end
 
 
 .sub 'main' :main
     .param pmc args
-    $P0 = compreg 'PMC'
+    $P0 = compreg 'Ops'
     .tailcall $P0.'command_line'(args, 'encoding'=>'utf8', 'transcode'=>'ascii')
 .end
 


More information about the parrot-commits mailing list